package com.example.yls.demoa;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;

import java.util.ArrayList;

class StudentApdter extends RecyclerView.Adapter<StudentViewHolder> {
    private ArrayList<Student> studentArrayList;

    public StudentApdter(ArrayList<Student> studentArrayList) {
        this.studentArrayList = studentArrayList;
    }

    @Override
    public StudentViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {

      View view = LayoutInflater.from(viewGroup.getContext())
              .inflate(R.layout.student_list_item,viewGroup,false);
      StudentViewHolder studentViewHolder = new StudentViewHolder(view);
        return studentViewHolder;
    }

    @Override
    public void onBindViewHolder(StudentViewHolder holder, int i) {
        Student student = studentArrayList.get(i);
        holder.nameView.setText(student.getName());
        holder.ageView.setText(String.valueOf(student.getAge()));
        Glide.with(holder.ivHead.getContext()).load(student.getHeadimg().getUrl())
            .into(holder.ivHead);
    }

    @Override
    public int getItemCount() {
        return studentArrayList.size();
    }
}
